/*   1:    */ package org.intellij.plugins.relaxNG.compact;
/*   2:    */ 
/*   3:    */

import com.intellij.codeInsight.TailType;
import com.intellij.codeInsight.completion.CompletionContext;
import com.intellij.codeInsight.completion.CompletionData;
import com.intellij.codeInsight.completion.CompletionVariant;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.lookup.TailTypeDecorator;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.patterns.StandardPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.filters.AndFilter;
import com.intellij.psi.filters.ContextGetter;
import com.intellij.psi.filters.ElementFilter;
import com.intellij.psi.filters.position.PatternFilter;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.intellij.plugins.relaxNG.compact.psi.RncDecl;
import org.intellij.plugins.relaxNG.compact.psi.RncDefine;
import org.intellij.plugins.relaxNG.compact.psi.RncElement;
import org.intellij.plugins.relaxNG.compact.psi.RncGrammar;
import org.intellij.plugins.relaxNG.compact.psi.util.EscapeUtil;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */ 
/*  32:    */ public class RncCompletionData
/*  33:    */   extends CompletionData
/*  34:    */ {
/*  35:    */   public RncCompletionData()
/*  36:    */   {
/*  37: 51 */     declareFinalScope(RncElement.class);
/*  38:    */     
/*  39: 53 */     CompletionVariant localCompletionVariant = new CompletionVariant(new AndFilter(new ElementFilter()
/*  40:    */     
/*  41:    */ 
/*  42:    */ 
/*  43:    */ 
/*  44:    */ 
/*  45:    */ 
/*  46: 60 */       new PatternFilter
/*  47:    */       {
/*  48:    */         public boolean isAcceptable(Object paramAnonymousObject, PsiElement paramAnonymousPsiElement)
/*  49:    */         {
/*  50: 56 */           return true;
/*  51:    */         }
/*  52:    */         
/*  53:    */         public boolean isClassAcceptable(Class paramAnonymousClass)
/*  54:    */         {
/*  55: 60 */           return PsiElement.class.isAssignableFrom(paramAnonymousClass);
/*  56:    */         }
/*  57: 60 */       }, new PatternFilter(StandardPatterns.or(new ElementPattern[] { PlatformPatterns.psiElement().afterLeaf(PlatformPatterns.psiElement(RncTokenTypes.KEYWORD_DEFAULT)), StandardPatterns.not(StandardPatterns.or(new ElementPattern[] { PlatformPatterns.psiElement().inside(PlatformPatterns.psiElement(RncTokenTypes.LITERAL)), PlatformPatterns.psiElement().afterLeaf(PlatformPatterns.psiElement().withElementType(RncTokenTypes.KEYWORDS)) })) }))));
/*  58:    */     
/*  59:    */ 
/*  60:    */ 
/*  61:    */ 
/*  62:    */ 
/*  63:    */ 
/*  64:    */ 
/*  65:    */ 
/*  66:    */ 
/*  67:    */ 
/*  68:    */ 
/*  69:    */ 
/*  70:    */ 
/*  71: 74 */     localCompletionVariant.includeScopeClass(LeafPsiElement.class, true);
/*  72:    */     
/*  73: 76 */     localCompletionVariant.addCompletion(new KeywordGetter(null));
/*  74:    */     
/*  75: 78 */     registerVariant(localCompletionVariant);
/*  76:    */   }
/*  77:    */   
/*  78:    */   private static class KeywordGetter
/*  79:    */     implements ContextGetter
/*  80:    */   {
/*  81: 82 */     private static final ElementPattern a = StandardPatterns.not(PlatformPatterns.psiElement().inside(PlatformPatterns.psiElement(RncGrammar.class).inside(true, PlatformPatterns.psiElement(RncGrammar.class))));
/*  82: 86 */     private static final PsiElementPattern b = (PsiElementPattern)PlatformPatterns.psiElement().inside(PlatformPatterns.psiElement(RncDecl.class));
/*  83: 89 */     private static final PsiElementPattern c = b.afterLeaf(PlatformPatterns.psiElement().withText("default"));
/*  84: 92 */     private static final ElementPattern d = StandardPatterns.and(new ElementPattern[] { PlatformPatterns.psiElement().withParent(RncDefine.class), PlatformPatterns.psiElement().afterLeafSkipping(PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement().withText("=")) });
/*  85: 95 */     private static final String[] e = { "default", "namespace", "datatypes" };
/*  86: 96 */     private static final String[] f = { "include", "div", "start" };
/*  87: 97 */     private static final String[] g = { "attribute", "element", "grammar", "notAllowed", "text", "empty", "external", "parent", "list", "mixed" };
/*  88:    */     
/*  89:    */     public Object[] get(PsiElement paramPsiElement, CompletionContext paramCompletionContext)
/*  90:    */     {
/*  91:101 */       ContainerUtil.map2Array(a(paramPsiElement), LookupElement.class, new Function()
/*  92:    */       {
/*  93:    */         public LookupElement fun(String paramAnonymousString)
/*  94:    */         {
/*  95:103 */           return TailTypeDecorator.withTail(LookupElementBuilder.create(paramAnonymousString).bold(), TailType.SPACE);
/*  96:    */         }
/*  97:    */       });
/*  98:    */     }
/*  99:    */     
/* 100:    */     private String[] a(PsiElement paramPsiElement)
/* 101:    */     {
/* 102:109 */       PsiElement localPsiElement = PsiTreeUtil.skipSiblingsForward(paramPsiElement, new Class[] { PsiWhiteSpace.class });
/* 103:110 */       if ((localPsiElement != null) && (EscapeUtil.unescapeText(localPsiElement).equals("="))) {
/* 104:111 */         return new String[] { "start" };
/* 105:    */       }
/* 106:114 */       if (c.accepts(paramPsiElement)) {
/* 107:115 */         return new String[] { "namespace" };
/* 108:    */       }
/* 109:116 */       if (b.accepts(paramPsiElement)) {
/* 110:117 */         return ArrayUtil.EMPTY_STRING_ARRAY;
/* 111:    */       }
/* 112:118 */       if (((paramPsiElement.getParent() instanceof RncDefine)) && (paramPsiElement.getParent().getFirstChild() == paramPsiElement))
/* 113:    */       {
/* 114:119 */         if (d.accepts(paramPsiElement)) {
/* 115:120 */           return ArrayUtil.EMPTY_STRING_ARRAY;
/* 116:    */         }
/* 117:122 */         if ((a.accepts(paramPsiElement)) && 
/* 118:123 */           (!b(paramPsiElement))) {
/* 119:124 */           return ArrayUtil.mergeArrays(e, ArrayUtil.mergeArrays(f, g));
/* 120:    */         }
/* 121:127 */         return f;
/* 122:    */       }
/* 123:129 */       return g;
/* 124:    */     }
/* 125:    */     
/* 126:    */     private boolean b(PsiElement paramPsiElement)
/* 127:    */     {
/* 128:134 */       return PsiTreeUtil.getPrevSiblingOfType(paramPsiElement.getParent(), RncDefine.class) != null;
/* 129:    */     }
/* 130:    */   }
/* 131:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.RncCompletionData

 * JD-Core Version:    0.7.0.1

 */